﻿// See https://aka.ms/new-console-template for more information

using ConsoleApp_EXL;
using ET;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.Text;

//获取文件夹路径
Console.WriteLine("输入文件夹路径");
string ?path = Console.ReadLine();


List<InputTableRow> rows = new List<InputTableRow>();   //源数据列表
//读取源表格
using (FileStream exlFile = new FileStream(path + "/IO.xlsx", FileMode.Open, FileAccess.Read))
{
    IWorkbook workBook = new XSSFWorkbook(exlFile);    //获取工作簿

    ISheet sheet = workBook.GetSheetAt(0);    //获取工作表

    IRow row = sheet.GetRow(0);

    //Console.WriteLine(row.LastCellNum);

    //Console.WriteLine(sheet.LastRowNum);

    //将源数据读取到实体类
    rows = GetClassInstances.GetClassInstancesFromTable(sheet);
} ;


//生成PLC变量表
GeneratePlcTags.GeneratePlcTagsFromTable(rows, path);

//生成数据块
GenerateDbBlock.GeberateDbBlockFromTable(rows, path);

//生成程序块
GenerateFcBlock.GenerateFcBlockFromTable(rows, path);

//生成HMI变量表
Console.WriteLine("输入HMI_连接_ 编号(不使用画面功能直接按 回车 )");
string con = Console.ReadLine()!;
if (con != "")
{
    GenerateHmiTags.GenerateHmiTagsFromTable(rows, path, "HMI_连接_" + con);

    //生成画面实例
    Console.WriteLine("输入画面宽度(默认 800 )");
    string width = Console.ReadLine()!;
    if (width == "")
    {
        width = "800";
    }
    Console.WriteLine("输入画面高度(默认 420 )");
    string height = Console.ReadLine()!;
    if (height == "")
    {
        height = "420";
    }
    CreatScreens.CreateScreensFromTable(rows, path, Convert.ToUInt16(height), Convert.ToUInt16(width));
}


Console.WriteLine("按任意键退出");

Console.ReadKey();